<template>
	<view class="container">
		<view class="cu-list menu-avatar">
			<!-- <view class="cu-item" @click="goNewsDetail">
				<view class="cu-avatar round lg" style="background-image:url(https://xzcs-public-files.oss-cn-beijing.aliyuncs.com/static/New-my/myNews-systeam.png);"></view>
				<view class="content">
					<view><view class="text-cut" style="font-weight: bold;">系统通知</view></view>
					<view class="text-gray text-sm flex"> 
						<view class="text-cut">
							<mp-html 
							:tagStyle="tagStyle"
							:content="systemData[0].info" 
							container-style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;"></mp-html>
						</view>
					</view>
				</view>
				<view class="action">
					<view class="text-grey text-sm">{{systemDate}}</view>
					<view v-if="systemCount > 0" class="cu-tag round bg-red sm">{{systemCount}}</view>
				</view>
			</view> -->
			<view class="cu-item" @click="goNoticeDetail">
				<view class="cu-avatar round lg" style="background-image:url(https://xzcs-public-files.oss-cn-beijing.aliyuncs.com/static/New-my/myNews-notice.png);"></view>
				<view class="content">
					<view>
						<view class="text-cut" style="font-weight: bold;">小竹公告</view>
					</view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">
							<mp-html 
							:content="noticeData[0].title" 
							container-style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;"></mp-html>
						</view>
					</view>
				</view>
				<view class="action">
					<view class="text-grey text-sm">{{noticeDate}}</view>
					<view v-if="noticeTrue" class="cu-tag round bg-red sm"></view>
				</view>
			</view>
			<view class="cu-item" @click="goActivityDetail">
				<view class="cu-avatar round lg" style="background-image:url(https://xzcs-public-files.oss-cn-beijing.aliyuncs.com/static/New-my/myNews-activity.png);"></view>
				<view class="content">
					<view><view class="text-cut" style="font-weight: bold;">活动通知</view></view>
					<view class="text-gray text-sm flex">
						<view class="text-cut">
							<mp-html 
							:content="activityData[0].title" 
							container-style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;"></mp-html>
						</view>
					</view>
				</view>
				<view class="action">
					<view class="text-grey text-sm">{{activityDate}}</view>
					<view v-if="activityTrue" class="cu-tag round bg-red sm"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import newsApi from "@/api/myNews.js"
	export default {
		data() {
			return {
				systemData: [],
				systemDate: '',
				systemCount: 0,
				noticeData: [],
				noticeDate: '',
				activityData: [],
				activityDate: '',
				noticeTrue: false,
				activityTrue: false,
				tagStyle: {
					em: 'font-style: normal;'
				}
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.getSystem()
			this.getSystemCount()
			this.getNotice()
			this.getActivity()
			setTimeout(() => {
				if(uni.getStorageSync('noticeNum') === this.noticeData.length) {
					this.noticeTrue = false
				}else {
					this.noticeTrue = true
				}
				if(uni.getStorageSync('activityNum') === this.activityData.length) {
					this.activityTrue = false
				}else {
					this.activityTrue = true
				}
			}, 500)
		},
		methods: {
			
			//获取系统通知数据
			async getSystem() {
				let obj = {
					type: 3,
					page: 1,
					pagesize: 10
				}
				let res = await newsApi.getmessage(obj)
				if(res.code === 1) {
					this.systemData = res.data
					this.systemDate = this.$moment(res.data[0].createtime*1000).format('MM-DD')
				}
			},
			//获取系统通知数量
			async getSystemCount() {
				let res = await newsApi.getmessage_count()
				if(res.code === 1) {
					this.systemCount = res.data.message
				}
			},
			
			//获取小竹公告数据
			async getNotice() {
				let res = await newsApi.getList({type: 1})
				if(res.code === 1) {
					this.noticeData = res.data
					this.noticeDate = this.$moment(res.data[0].createtime*1000).format('MM-DD')
				}
			},
			
			//获取小竹公告数据
			async getActivity() {
				let res = await newsApi.getList({type: 2})
				if(res.code === 1) {
					this.activityData = res.data
					this.activityDate = this.$moment(res.data[0].createtime*1000).format('MM-DD')
				}
			},
			
			//跳转系统通知列表
			async goNewsDetail() {
				let res = await newsApi.clearunread()
				if(res.code === 1) {
					console.log('没进来吗')
					uni.navigateTo({
						url: '/pagesMy3/newsDetail/newsDetail'
					})
				}
			},
			
			//跳转小竹公告列表
			goNoticeDetail() {
				uni.setStorageSync('noticeNum', this.noticeData.length)
				uni.navigateTo({
					url: '/pagesMy3/noticeDetail/noticeDetail'
				})
			},
			
			//跳转活动通知列表
			goActivityDetail() {
				uni.setStorageSync('activityNum', this.activityData.length)
				uni.navigateTo({
					url: '/pagesMy3/activityNotice/activityNotice'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
@import 'myNews.scss';
</style>
